@extends('layouts.console_header')

@section('title', '已上架商家列表')

@section('resources')
    @parent
    <link rel="stylesheet" href="{{env('CSS_DOMAIN')}}css/jquery.dataTables.min.css?v={{env('CSS_VERSION')}}">
    <style>
        .shop_eweima{position: fixed;top: 200px;left: 50%;width: 550px;padding-bottom: 10px;margin-left: -275px;background-color: #fff;border: 1px solid #333;display: none;z-index: 1001;}
        .shop_eweima_content li{text-align: center;margin: 10px;}
        .shop_eweima .shop_downloadewm{width: 350px;height: 40px;margin: 0 125px;background-color: #9955c6;color: #fff;border-radius: 10px;position: absolute;bottom: 20px;}
        .shop_title{height: 50px;line-height: 50px;border-bottom: 1px solid #333;}
        .shop_title p{width: 500px;text-align: center;}
        .shop_title img{width: 30px;margin: 10px;}
        .down_eweimas{width: 120px;height: 30px;line-height: 30px;margin: 9px 15px;border-radius: 5px;background: #9955c6;color: #fff;font-size: 14px;cursor: pointer;}
        .prompt_double{width: 500px;position: fixed;top: 200px;left: 50%;margin-left: -250px;background-color: #fff;z-index: 1001;box-shadow: 0px 0px 5px 5px rgba(128,128,128,0.5);}
        .prompt_double .title{font-size: 24px;margin-top: 10px;color: #9955c6;text-align: center;}
        .prompt_double .content{font-size: 18px;color: #808080;margin-top: 40px;padding: 0 60px;text-align: center;}
        .new_shop_eweima_content .content{font-size: 18px;color: #808080;margin-top: 40px;padding: 0 60px;text-align: center;}
        .prompt_double .content input{font-size: 14px;width: 300px;height: 30px;border: 1px solid #000;padding: 0 5px;}
        .new_shop_eweima_content .content input{font-size: 14px;width: 300px;height: 30px;border: 1px solid #000;padding: 0 5px;}
        .prompt_double .close_pic{width: 30px;height: 30px;position: absolute;top: 10px;right: 10px;}
        .prompt_double .button{margin-top: 30px;font-size: 24px;}
        .new_shop_eweima_content .button{margin-top: 30px;font-size: 24px;}
        .prompt_double .button button{width: 100px;height: 40px;text-align: center;line-height: 40px;border-radius: 5px;cursor: pointer;}
        /*.new_shop_eweima_content .button button{width: 100px;height: 40px;text-align: center;line-height: 40px;border-radius: 5px;cursor: pointer;}*/
        .prompt_double .button .cancel{margin: 10px 0 30px 20px;background-color: #eee;}
        .new_shop_eweima_content .button .new_shop_cancel{margin: 10px 0 30px 20px;background-color: #eee;width: 100px;height: 40px;text-align: center;line-height: 40px;border-radius: 5px;cursor: pointer;}
        .prompt_double .button .sure{margin: 10px 20px 30px 0;cursor: pointer;}
        .new_shop_eweima_content .button .sure{margin: 10px 20px 30px 0;cursor: pointer;}
        .prompt_success{width: 100px;position: fixed;top: 250px;left: 50%;margin-left: -60px;background: rgba(0,0,0,0.5);padding: 10px;z-index: 1002;text-align: center;color: #fff;display: none;}
        .prompt_double .count_down{font-size: 18px;color: red;margin-top: 10px;padding: 0 60px;text-align: center;display: none;}
        .new_shop_eweima{border-bottom: 1px solid #aaa;padding: 0 10px;cursor: pointer;}
    </style>
@endsection

@section('content')
<section class="user_list">
    <div style="border-bottom: 2px solid #9955c6;overflow: hidden;">
        <p class="fz_14 account_title fl" style="border: none;"><span style="color: #7f7f7f;"><a href="/console/index">首页</a>>商家版运营></span><span class="co_violet">已上架商家列表</span></p>
        <a href="/console/shop/new?cityid={{$cityid}}" target="_blank"><p class="fr tc back_btn">+新增</p></a>
        <p class="fr tc down_eweimas">批量生成二维码</p>
    </div>
    <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>序号</th>
                <th>商家代码</th>
                <th>商家名称</th>
                <th>商家登录账号</th>
                <th>一级分类</th>
                <th>二级分类</th>
                <th>区县</th>
                <th>商圈</th>
                {{--<th>翻倍日</th>--}}
                <th>商务姓名</th>
                <th>二维码编号</th>
                <th>入驻日期</th>
                <th style="width: 130px;">操作</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>序号</th>
                <th>商家代码</th>
                <th>商家名称</th>
                <th>商家登录账号</th>
                <th>一级分类</th>
                <th>二级分类</th>
                <th>区县</th>
                <th>商圈</th>
                {{--<th>翻倍日</th>--}}
                <th>商务姓名</th>
                <th>二维码编号</th>
                <th>入驻日期</th>
                <th>操作</th>
            </tr>
        </tfoot>
        <tbody>
            @foreach($lists as $list)
                <tr>
                @if(!isset($i))
                    <td>{{$i=1}}</td>
                @else
                    <td>{{++$i}}</td>
                @endif
                    {{--<td>{{$list['shopid']}}</td>--}}
                    <td>{{$list['shopcode']}}</td>
                    <td>{{$list['shopname']}}</td>
                    <td>{{$list['parentmobile']}}</td>
                    <td>{{$list['firstclassname']}}</td>
                    <td>{{$list['secondclassname']}}</td>
                    <td>{{$list['districtname']}}</td>
                    <td>{{$list['businessareaname']}}</td>
                {{--@if(($list['todayevent'] == '0') && ($list['lastevent'] == '0000-00-00'))--}}
                    {{--<td>未设置</td>--}}
                {{--@else--}}
                    {{--<td>已设置</td>--}}
                {{--@endif--}}
                    <td>{{$list['realname']}}</td>
                    <td>{{$list['qrcode']}}</td>
                    <td>{{date('Y-m-d', strtotime($list['created_at']))}}</td>
                    <td>
                        <a class="co_violet" href="/console/shop/get?cityid={{$cityid}}&shopid={{$list['shopid']}}">详情</a>
                    @if($list['todayevent'] == '1')
                        <a href="#" style="margin: 0 10px;color: red;" onclick="cancel_double({{$list['shopid']}})">取消今日翻倍</a>
                    @else
                        <a class="co_violet" href="#" style="margin: 0 10px;" onclick="open_double({{$list['shopid']}})">开通今日翻倍</a>
                    @endif
                        <a href="#" style="margin-right: 10px;color: red;" onclick="off_the_shelf({{$list['shopid']}})">下架</a>
                    @if($list['qrcode'] != '')
                        <a class="co_violet" href="#" style="margin-right: 10px;" onclick="shop_eweima('{{$list['shopid']}}','{{$list['shopname']}}','{{$list['address']}}','{{$list['qrcode']}}')">二维码</a>
                    @else
                        <a class="co_violet" href="#" style="margin-right: 10px;" onclick="bindeweima('{{$list['shopid']}}')">绑定二维码</a>
                    @endif
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</section>
<div class="hot_search_mark hot_search_mark1">
    <p class="oh">
        <span class="fl content">取消今日翻倍</span>
        <img class="fr close" src="{{env('IMAGE_DOMAIN')}}images/close_p.png" alt="">
    </p>
    <div style="padding: 0 10px;height: 98px;">
        <div style="display: none;">
            <span>理由：</span>
            <select style="border: 1px solid #808080;padding: 5px 10px;" name="deductiontype" id="">
                <option value="0">扣除今日</option>
                <option value="1">扣除一半</option>
                <option value="2">扣除全部</option>
            </select>
        </div>
        <div class="oh" style="margin-top: 30px;">
            <span class="fl">备注:</span>
            <textarea class="fl remark" style="border: 1px solid #808080;width: 290px;height: 50px;margin-left: 10px;padding: 5px;" name="deductionnote" id="deductionnote" cols="30" rows="10"></textarea>
        </div>
    </div>
    <p>
        <button style="background-color: #9955c6;color: #fff;" class="sure fl">确定</button>
        <button class="cancel fr">取消</button>
    </p>
</div>
<div class="hot_search_mark hot_search_mark2">
    <p class="oh">
        <span class="fl content">开通今日翻倍</span>
        <img class="fr close" src="{{env('IMAGE_DOMAIN')}}images/close_p.png" alt="">
    </p>
    <p>
        确定开通翻倍日？
    </p>
    <p>
        <button style="background-color: #9955c6;color: #fff;" class="sure fl">确定</button>
        <button class="cancel fr">取消</button>
    </p>
</div>
<!-- 二维码  -->
<form action="" method="" class="shop_eweima">
    <div class="shop_title oh">
        <p class="fl">商家收款二维码</p>
        <img class="fr shop_close" src="{{env('IMAGE_DOMAIN')}}images/close_p.png" alt="">
    </div>
    <ul class="shop_eweima_content">
        <li id="output"></li>
        <li class="co_violet" style="font-size: 20px;"><span>门店名称 ：</span><span class="eweimashopname"></span></li>
        <li class="fz_16 co_gray56"><span>门店地址 ：</span><span class="eweimashopaddress"></span></li>
        <li class="fz_16" style="color: #aaa;"><span class="new_shop_eweima">绑定新的二维码</span></li>
    </ul>
    <div class="new_shop_eweima_content" style="display: none;">
        <p class="content">
            <!-- <input type="hidden" name="shopid" value="">  -->
            <input type="text" name="qrcode" value="" placeholder="请输入二维码编号或使用扫描枪识别二维码">
        </p>
        <p class="button oh">
            <input type="button" name="" value="取消" class="fl new_shop_cancel">
            <input type="button" name="" value="确定" class="fr sure">
        </p>
    </div>
</form>
@endsection

@section('scriptResources')
    @parent
    <script type="text/javascript" src="{{env('JS_DOMAIN')}}js/jquery.qrcode.min.js"></script>
    <script src="{{env('JS_DOMAIN')}}js/jquery.dataTables.min.js?v={{env('JS_VERSION')}}"></script>
    <script>
        var cityid = '{{$cityid}}';
        var weburl = '{{env('WEB_URL')}}';
        var bindEweima = $('<form action="" method="" class="prompt_double">'+
                            '<img class="fr close_pic" src="{{env('IMAGE_DOMAIN')}}images/close_p.png" alt="">'+
                            '<p class="title">绑定二维码</p>'+
                            '<p class="content"><input type="hidden" name="shopid" value="">' +
                            '<input type="text" name="qrcode" value="" placeholder="请输入二维码编号或使用扫描枪识别二维码"></p>'+
                            '<p class="button oh">'+
                                '<input type="button" name="" value="取消" class="fl cancel">'+
                                '<input type="button" name="" value="确定" class="fr sure">'+
                            '</p>'+
                        '</form>');
        var downEweima = $('<form action="" method="" class="prompt_double">'+
                            '<img class="fr close_pic" src="{{env('IMAGE_DOMAIN')}}images/close_p.png" alt="">'+
                            '<p class="title">批量生成二维码</p>'+
                            '<p class="content">批量生成100个二维码，新生成的二维码未绑定任何商家。是否生成并打包下载二维码？</p>'+
                            '<p class="count_down">正在启动下载...倒计时<span class="count_down_time">5</span>秒</p>'+
                            '<p class="button oh">'+
                                '<input type="button" name="" value="取消" class="fl cancel">'+
                                '<a href="/console/shop/qrcode/batch/generate?cityid={{$cityid}}&count=100"><input type="button" name="" value="确定" class="fr sure"></a>'+
                            '</p>'+
                        '</form>');
        $(document).ready(function() {
            $('#example').DataTable();
            $(".close").click(function(){
                $(this).parent().parent().hide();
            })
        });
        $(".shop_close").on('click',function(){
            $(this).parent().parent().hide();
            $(".public_prompt_mark").hide();
        })
        //批量下载二维码
        $(".down_eweimas").click(function(){
            $(".public_prompt_mark").show();
            $(".public_prompt_mark").height($(window).height());
            $('body').append(downEweima);
            $(".prompt_double .sure").click(function(){
                $(".prompt_double .sure").unbind("click");
                $(".count_down").show();
                var countDownTime=3;
                $(".count_down_time").html(countDownTime);
                var countDownTimer = setInterval(function(){ 
                    if(countDownTime == 0){
                        clearInterval(countDownTimer);
                        $(".public_prompt_mark").hide();
                        $(".count_down").hide();
                        $(".prompt_double").remove();
                    }else{
                        countDownTime--;
                        $(".count_down_time").html(countDownTime);
                    }
                },1000);
            });
            $(".prompt_double .cancel").click(function(){
                $(".count_down").hide();
                $(".public_prompt_mark").hide();
                $(".prompt_double").remove();
            });
            $(".prompt_double .close_pic").click(function(){
                $(".count_down").hide();
                $(".public_prompt_mark").hide();
                $(".prompt_double").remove();
            });
        })
        //绑定二维码
        function bindeweima(shopid){
            $(".public_prompt_mark").show();
            $(".public_prompt_mark").height($(window).height());
            $('body').append(bindEweima);
            $(".prompt_double input[name='shopid']").val(shopid);
            $(".prompt_double .sure").click(function(){
                var shopqrcode=$(".prompt_double input[name='qrcode']").val();
                var shopid=$(".prompt_double input[name='shopid']").val();
                if(shopqrcode == '') {
                    alert("请输入二维码编号"); return;
                }
                $.ajax({
                    url : '/console/shop/qrcode/binding',
                    type : 'post',
                    data: {
                        cityid:cityid,
                        shopid:shopid,
                        qrcode:shopqrcode
                    },
                    dataType:'json',
                    async: true,
                    success:function(data){
                        if(data.status == 'success') {
                            alert(data.message);
                            window.location.reload();
                        } else {
                            alert(data.message);
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {

                    }
                });
            });
            $(".prompt_double .cancel").click(function(){
                $(".public_prompt_mark").hide();
                $(".prompt_double").remove();
            });
            $(".prompt_double .close_pic").click(function(){
                $(".public_prompt_mark").hide();
                $(".prompt_double").remove();
            });
        }
        //重新绑定二维码
        function new_shop_eweima(shopid){
            $(".shop_eweima_content").hide();
            $(".new_shop_eweima_content").show();
            $(".new_shop_eweima_content .sure").click(function(){
                var shopqrcode=$(".new_shop_eweima_content input[name='qrcode']").val();
                // var shopid=$(".new_shop_eweima_content input[name='shopid']").val();
                if(shopqrcode == '') {
                    alert("请输入二维码编号"); return;
                }
                $.ajax({
                    url : '/console/shop/qrcode/binding',
                    type : 'post',
                    data: {
                        cityid:cityid,
                        shopid:shopid,
                        qrcode:shopqrcode
                    },
                    dataType:'json',
                    async: true,
                    success:function(data){
                        if(data.status == 'success') {
                            alert(data.message);
                            window.location.reload();
                        } else {
                            alert(data.message);
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {

                    }
                });
            });
        }
        $(".new_shop_cancel").click(function(){
            $(".shop_eweima_content").show();
            $(".new_shop_eweima_content").hide();
            $(".new_shop_eweima_content input[name='qrcode']").val('');
            $(".new_shop_eweima_content input[name='shopid']").val('');
        })
        // 二维码  
        function shop_eweima(shopid, shopname, address, qrcode){
            $('#output').html("");
            $(".eweimashopname").text(shopname);
            $(".eweimashopaddress").text(address);
            $(".shop_eweima").show();
            $(".shop_eweima_content").show();
            $(".public_prompt_mark").show();
            $(".public_prompt_mark").height($(window).height());
            $(".new_shop_eweima_content").hide();
            //var qrcode = JSON.stringify({type:'payment', content:shopid});
            //var qrcodeurl = weburl + "qrcode/shop/" + shopid;
            var qrcodeurl = weburl + "qrcode/shop/" + qrcode;
            $('#output').qrcode(qrcodeurl);
            $(".new_shop_eweima").click(function(){
                new_shop_eweima(shopid);
            })
        }
        function cancel_double(shopid) {
            $('.hot_search_mark1').show();
            $('.content').html('取消翻倍日');
            $('.sure').click(function(){
                var deductiontype = 0;
                var deductionnote=$("textarea[name='deductionnote']").val();
                $.ajax({
                    url : '/console/shop/event/today/update',
                    type : 'post',
                    data: {
                        'shopid':shopid,
                        'cityid':cityid,
                        'type': '0',
                        'deductiontype':deductiontype,
                        'deductionnote':deductionnote
                    },
                    dataType:'json',
                    success:function(data){
                        if(data.status == 'success') {
                            alert(data.message);
                            location.reload();
                        } else {
                            alert(data.message);
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
                });
            })
            $('.cancel').click(function(){
                $('.hot_search_mark1').hide();
            })
        }
        function open_double(shopid) {
            $('.hot_search_mark2').show();
            $('.content').html('开通翻倍日');
            $('.sure').click(function(){
                $.ajax({
                    url : '/console/shop/event/today/update',
                    type : 'post',
                    data: {
                        'shopid':shopid,
                        'cityid':cityid,
                        'type': '1'
                    },
                    dataType:'json',
                    success:function(data){
                        if(data.status == 'success') {
                            alert(data.message);
                            location.reload();
                        } else {
                            alert(data.message);
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
                });
            })
            $('.cancel').click(function(){
                $('.hot_search_mark2').hide();
            })
        }
        function off_the_shelf(shopid) {
            // var is_confirm = confirm("确定下架吗？");
            var note = '商家下架';
            $('.hot_search_mark1').show();
            $('.content').html(note);
            $('.sure').click(function(){
                var deductiontype=0;
                var deductionnote=$("textarea[name='deductionnote']").val();
                $.ajax({
                    url : '/console/shop/downshelf',
                    type : 'post',
                    data: {
                        'shopid':shopid,
                        'cityid':cityid,
                        'note': note,
                        'deductiontype':deductiontype,
                        'deductionnote':deductionnote
                    },
                    dataType:'json',
                    success:function(data){
                        if(data.status == 'success') {
                            alert(data.message);
                            location.reload();
                        } else {
                            alert(data.message);
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
                });
            })
            $('.cancel').click(function(){
                $('.hot_search_mark1').hide();
            })
        }
    </script>
@endsection